package logic

import (
	"8-dshop/cache"
	"context"

	"8-dshop/shoprpc/internal/svc"
	"8-dshop/shoprpc/shoprpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CarDelLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCarDelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CarDelLogic {
	return &CarDelLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CarDelLogic) CarDel(in *shoprpc.CarDelRequest) (*shoprpc.CarDelResponse, error) {
	// todo: add your logic here and delete this line
	if in.ProductId == 0 {
		if err := cache.CarDel(in.UserId); err != nil {
			return nil, err
		}
	} else {
		if err := cache.CarDelProduct(in.UserId, in.ProductId); err != nil {
			return nil, err
		}
	}
	return &shoprpc.CarDelResponse{}, nil
}
